class @AdminCategoryCreateView extends CustomView

    el: $('#content')

    initialize: ->
        super

    render: ->
        el = $(@el)

        @GetTemplate(SiteMap.Admin.Categories.CreateTemplate, (compiledTemplate) =>
            el.html(compiledTemplate(@model.toJSON()))
        )

    events:
        "click .buttons>button.save": "save"
        "click .buttons>button.cancel": "cancel"

    save: (event) ->
        event.preventDefault()
        Loading.Start()
        Messages.WriteMessage('Creating category.')

        data = $(@el).find("form.general").serialize()

        $.post(SiteMap.Admin.Categories.Create, data, (response)=>
            if response.SuccessMessage? && response.SuccessMessage.length
                Messages.WriteSuccessMessage(response.SuccessMessage)
                @Navigate(SiteMap.Admin.Categories.Listing, true)
            else
                Messages.WriteErrors(response.Errors);
                Loading.Stop();
        );

    cancel: (event) ->
        event.preventDefault()
        Loading.Start()
        Messages.Clear()
        @Navigate(SiteMap.Admin.Categories.Listing, true)
